#!/bin/bash

echo "=== VimL虚拟机阶段一优化效果测试 ==="
echo

# 测试函数
test_performance() {
    local test_name="$1"
    local test_file="$2"
    local expected_result="$3"
    
    echo "测试: $test_name"
    echo "文件: $test_file"
    
    # 执行测试并记录时间
    start_time=$(date +%s.%N)
    result=$(./build/bin/vimlc "$test_file" 2>/dev/null | tail -2 | head -1)
    end_time=$(date +%s.%N)
    
    # 计算执行时间
    execution_time=$(echo "$end_time - $start_time" | bc -l)
    
    echo "结果: $result"
    echo "执行时间: ${execution_time}s"
    
    # 验证结果
    if [ "$result" = "$expected_result" ]; then
        echo "✅ 结果正确"
    else
        echo "❌ 结果错误，期望: $expected_result"
    fi
    
    echo "----------------------------------------"
    echo
}

# 性能基准测试
echo "开始性能测试..."
echo

test_performance "斐波那契数列(10)" "example/recursive_fibonaccy.vim" "55"
test_performance "斐波那契数列(20)" "example/fib20.vim" "6765"
test_performance "斐波那契数列(25)" "example/fib25.vim" "75025"

echo "=== 性能测试完成 ==="
echo
echo "预期优化效果:"
echo "- 数值运算优化: +20-40% (内联化类型检查，快速路径)"
echo "- 常量加载优化: +5-15% (预分配常用值)"
echo "- MOVE指令优化: +5-15% (避免不必要拷贝)"
echo "- 跳转指令优化: +5-10% (减少调试检查)"
echo "- 综合预期提升: 30-80%"